home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / utility / blrmu13.zip / PRT.ASM < prev    next >
Assembly Source File  |  1992-01-09  |  7KB  |  261 lines

  1. page ,132
  2. title prt ( multiple text file printer ) as of 01/09/92 - 09:25 pm
  3. ;*------------------------------------------
  4. ;
  5. ;        print multiple text file copies
  6. ;
  7. ;        syntax : prt n xxx.xxx
  8. ;
  9. ;        where n = 1 - 9 copies
  10. ;        where xxx.xxx = text file name
  11. ;
  12. ;*------------------------------------------
  13.          .model small
  14.          .code
  15. ;*------------------------------------------
  16.          include iomac.lib
  17. ;*------------------------------------------
  18. ;
  19. mfs      equ   32000         ; max file size
  20. ;
  21. ;*---------------------------
  22. ;   definition of cmd line
  23. ;*---------------------------
  24.          org   128
  25. ;
  26. pl       db    0             ; parm len
  27.          db    0             ; space
  28. amt      db    0             ; amt ( of copies )
  29.          db    0
  30. fn       db    70 dup (0)    ; file name
  31. ;
  32. ;*------------------------
  33. ;   start of pgm
  34. ;*------------------------
  35.          org   256
  36. go:
  37.          jmp   prt
  38. ;
  39. ;*-----------------------
  40. ;    data declarations
  41. ;*-----------------------
  42. fpm      db    13,10,10,' * PRTing '
  43. fpnc     db    'x'
  44.          db    ' copies of '
  45. fnv      db    50 dup (' ')
  46.          db    13,10,10,'$'
  47. ;
  48. sm       db    13,10,10,' * syntax : prt n xxx.xxx'
  49.          db    13,10,' * where n = 1 - 9, and xxx.xxx = text file name'
  50.          db    13,10,10,'$'
  51. ;
  52. fh       dw    0             ; file handle
  53. scx      dw    0             ; save cx
  54. abr      dw    0             ; actual bytes read
  55. filenlo  dw    0             ; file len lo
  56. filenhi  dw    0             ; file len hi
  57. ;
  58. ;   error messages
  59. ;
  60. npem     db    13,10,10,' * ERROR - no parameters ! * $'
  61. plem     db    13,10,10,' * ERROR - invalid parameter length ( no file name ? ) * $'
  62. ofem     db    13,10,10,' * ERROR - while opening file ! * $'
  63. rfem     db    13,10,10,' * ERROR - while reading file ! * $'
  64. ftlem    db    13,10,10,' * ERROR - File Too Large ( max size = 32000 bytes ) ! * $'
  65. ;
  66. ;*--------------------
  67. ;   start of code
  68. ;*--------------------
  69. prt:
  70. ;
  71.          cmp   pl,0          ; no parm
  72.          je    em1           ; if so, err 1 exit
  73. ;
  74.          cmp  pl,2           ; 1 digit + space ?
  75.          jng  em2            ; if not, err 2 exit
  76. ;
  77. ;   get file name and count for display
  78. ;
  79.          lea   si,fn         ; ptr to srs
  80.          lea   di,fnv        ; ptr to dest
  81.          mov   cl,pl         ; parm len
  82.          mov   ch,0          ; clr hi byte
  83.          sub   cx,3          ; adjust len
  84.          cld
  85.          rep   movsb         ; move it
  86.          mov   al,amt        ; get amt
  87.          mov   fpnc,al       ; to msg
  88.          jmp   pod           ; process one digit
  89. ;
  90. em1:
  91.          lea  dx,npem        ; no parm err msg
  92.          jmp  pmcex
  93. em2:
  94.          lea  dx,plem        ; parm len err msg
  95.          jmp  pmcex
  96. em3:
  97.          lea  dx,ofem        ; open file err msg
  98.          jmp  pmcex
  99. em4:
  100.          lea  dx,rfem        ; read file err msg
  101.          jmp  pmcex
  102. emtl:
  103.          lea  dx,ftlem       ; file too large err msg
  104.          jmp  pmcex
  105. ;
  106. ;   process one digit
  107. ;
  108. pod:
  109. ;
  110.          cld                 ; forward
  111.          lea   si,amt        ; ptr to amt
  112.          lodsb               ; put it in al
  113.          and   al,15         ; make ascii binary
  114.          mov   ch,0          ; clear ch
  115.          mov   cl,al         ; mov al to cl
  116. ;
  117. ;        validate amt between 1 - 9
  118. ;
  119.          cmp   cl,1          ; amt = 1 ?
  120.          jl    ma1           ; if LT, make amt 1
  121. ;
  122.          cmp   cl,9          ; amt = 9 ?
  123.          jg    ma1           ; if GT, make amt 1
  124. ;
  125.          jmp   sc            ; ok, carry on
  126. ;
  127. ;  make amt 1
  128. ;
  129. ma1:
  130.          mov   cl,1          ; set copy amt to 1
  131. ;
  132. ;   save cx
  133. ;
  134. sc:
  135.          mov   scx,cx        ; save copy amt
  136. ;
  137.          oaif  fn,0          ; open the text file
  138. ;
  139.          jnc   mfh           ; if carry not set, carry on
  140.          jmp   em3           ; err exit 3
  141. ;
  142. mfh:
  143. ;
  144.          mov   fh,ax         ; save file handle
  145. ;
  146. ;   check if file size too large
  147. ;
  148.          mfpffs fh,0,0,2
  149. ;
  150.          cmp   filenhi,0
  151.          ja    emtl
  152.          cmp   filenlo,mfs
  153.          ja    emtl
  154. ;
  155.          caf   fh            ; close file
  156.          oaif  fn,0          ; open it again
  157. ;
  158.          raf   fh,fia,mfs    ; read the text file
  159. ;
  160.          jnc   pf            ; if carry not set, carry on
  161.          jmp   em4           ; err exit 4
  162. ;
  163. pf:
  164.          mov   abr,ax        ; save actual byte read
  165. ;
  166.          lea   dx,fpm        ; ptr to msg
  167.          call  dasts         ; display a string to scrn
  168. ;
  169. ;   number of copies loop
  170. ;
  171. nocl:
  172. ;
  173.          call  tof           ; top of form
  174. ;
  175.          lea   si,fia        ; ptr to file input area
  176.          mov   cx,abr        ; set cnt to actual bytes read
  177.          cld                 ; forward
  178. ;
  179. ;   prt out loop
  180. ;
  181. pol:
  182. ;
  183.          lodsb               ; get a byte
  184.          mov   dl,al         ; and send it
  185.          mov   ah,5          ; to prtr
  186.          int   33
  187.          loop  pol           ; abr times
  188. ;
  189.          call  cr            ; CR
  190.          call  lf            ; LF
  191.          call  lf            ; LF
  192. ;
  193.          mov   cx,scx        ; get copies cnt
  194.          cmp   cx,1          ; 1 ?
  195.          je    pmcx          ; if so, thru
  196.          dec   cx            ; cnt - 1
  197.          mov   scx,cx        ; save it again
  198.          jmp   nocl          ; do it again
  199. ;
  200. ;   normal exit
  201. ;
  202. pmcx:
  203.          call  tof           ; top of form
  204. pmcxe:
  205.          caf   fh            ; close the file
  206.          mov   al,0          ; set cond code to 0
  207.          mov   ah,76         ; exit
  208.          int   33
  209. ;
  210. ;   error exit
  211. ;
  212. pmcex:
  213. ;
  214.          call  dasts         ; display passed string to scrn
  215. ;
  216.          lea   dx,sm         ; ptr to syntax msg
  217.          call  dasts         ; display it
  218. ;
  219.          jmp   pmcxe         ; and exit
  220. ;
  221. ;    Top of Form
  222. ;
  223. tof      proc  near
  224.          mov   dl,12
  225.          mov   ah,5
  226.          int   33
  227.          ret
  228. tof      endp
  229. ;
  230. ;   Line Feed
  231. ;
  232. lf       proc  near
  233.          mov   dl,10
  234.          mov   ah,5
  235.          int   33
  236.          ret
  237. lf       endp
  238. ;
  239. ;   Carriage Return
  240. ;
  241. cr       proc  near
  242.          mov   dl,13
  243.          mov   ah,5
  244.          int   33
  245.          ret
  246. cr       endp
  247. ;
  248. ;   Display A String To Screen
  249. ;
  250. dasts    proc  near
  251.          mov   ah,9
  252.          int   33
  253.          ret
  254. dasts    endp
  255. ;
  256. ;   file input area
  257. ;
  258. fia      db    0
  259. ;
  260.          end   go
  261.